import QtQuick 2.6
import QtQuick.Layouts 1.3
import Qt.labs.controls 1.0
import QtQuick.XmlListModel 2.0
import "../template" as Template
Template.PopupFrame {
    id:view

    signal callback (string date, string time1, string time2, var course, var place, string description)
    contentHeight: 420
    title: "签到"
    Pane {
        ColumnLayout {
            id: col
            anchors.fill: parent
            anchors.margins: 9
            spacing: 12
            RowLayout {
                Label {id: labelText; font.pixelSize: 14; text: "日期："}

                TextField {
                    id: labelDate

                    Layout.alignment: Qt.AlignVCenter

                    Layout.fillWidth: true
                    readOnly: true
                    text: Qt.formatDate(new Date(), "yyyy-MM-dd")
                }
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.leftMargin: 9
                anchors.rightMargin: 9
            }
            RowLayout {
                Label {font.pixelSize: 14; text: "起始："}


                ComboBox {
                    id: tum1_1
                    model: ["06", "07", "08", "09","10", "13", "14", "15","16"]
                    Layout.preferredWidth: 96
                }
                Label {text: "点"}
                ComboBox {
                    id: tum1_2
                    model: ["00", "30"]
                    Layout.preferredWidth: 96
                }
                Label {text: "分"}

            }

            RowLayout {
                Label { font.pixelSize: 14; text: "时间："}

                ComboBox {
                    id: tum2_1
                    model: ["06", "07", "08", "09","10", "13", "14", "15","16"]
                    Layout.preferredWidth: 96
                }
                Label {text: "点"}
                ComboBox {
                    id: tum2_2
                    model: ["00", "30"]
                    Layout.preferredWidth: 96
                }
                Label {text: "分"}
            }

            RowLayout {
                Label {font.pixelSize: 14; text: "场地："}

                ComboBox {
                    id: labelPlace

                    Layout.alignment: Qt.AlignVCenter

                    Layout.fillWidth: true
                    model:     XmlListModel {
                        id: xmlModelPlace
                        source: http.build("/place.xml",{})
                        query: "/places/place"

                        XmlRole { name: "id"; query: "id/string()" }
                        XmlRole { name: "name"; query: "name/string()" }
                    }
                    textRole:  "name"
                    currentIndex: 0
                }

            }

            RowLayout {
                Label {font.pixelSize: 14; text: "课程："}

                ComboBox {
                    id: labelCourse

                    Layout.alignment: Qt.AlignVCenter

                    Layout.fillWidth: true
                    model:     XmlListModel {
                        id: xmlModelCourse
                        source: http.build("/course.html", {})
                        query: "/courses/course"

                        XmlRole { name: "id"; query: "id/string()" }
                        XmlRole { name: "name"; query: "name/string()" }
                    }
                    textRole:  "name"
                    currentIndex: 0
                }

            }

            RowLayout {
                Label {font.pixelSize: 14; text: "说明："}

                TextField {
                    id: labelDescription

                    Layout.alignment: Qt.AlignVCenter

                    Layout.fillWidth: true
                }

            }


        }
    }


    onClicked: {
        callback(labelDate.text,
                 tum1_1.model[tum1_1.currentIndex] + ":" + tum1_2.model[tum1_2.currentIndex],
                 tum2_1.model[tum2_1.currentIndex] + ":" + tum2_2.model[tum2_2.currentIndex],
                 xmlModelCourse.get(labelCourse.currentIndex),
                 xmlModelPlace.get(labelPlace.currentIndex),
                 labelDescription.text)
        view.close()
    }



}

